﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using cmsservice.Entity;
using cmsservice.BLL;
using cmsservice.Common.Memcached;
using System.Text;
using cmsservice.DAL;
using cmsservice.Common;

/// <summary>
///softnews 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class softnews : System.Web.Services.WebService
{

    public softnews()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    string cachePre = "2121";

    [WebMethod(Description = "软件分类报价")]
    public List<Em_Grab_GaoTime_Zx> softflbj(string stock)
    {
        try
        {
            string key = "softnews_Em_Grab_GaoTime_Zx_" + cachePre + "_" + stock;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var lst = newsCacheTools.Get<List<Em_Grab_GaoTime_Zx>>(key);
            if (lst != null)
            {
                return lst;
            }
            else
            {
                Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
                lst = bll.Get股票分类报价New(stock);
                newsCacheTools.Add(key, lst, 0, 30, 0);
                return lst;
            }
           
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "softflbj", stock);
            throw ex;
        }
    }

    [WebMethod(Description = "软件分类报价股票代码列表")]
    public string softflbjstock()
    {
        try
        {
            string key = "softnews_softflbjstock";
            News2CacheTools newsCacheTools = new News2CacheTools();
            string str = newsCacheTools.Get<string>(key);
            if (str != null)
            {
                return str;
            }
            else
            {
                CommonBLL cbll = new CommonBLL();
                var lst = cbll.DicStock.Keys.ToList();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < lst.Count; i++)
                {
                    sb.Append(lst[i]);
                    if (i < lst.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                str = sb.ToString();
                newsCacheTools.Add(key, str, 4, 0, 0);
            }
            return str;
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "softflbjstock", "");
            throw ex;
        }
    }

    [WebMethod(Description = "F10公告")]
    public List<Em_Grab_GaoTime_Zx> f10gonggao(string stock)
    {
        try
        {
            string key = "softnews_f10gonggao_New_" + cachePre + "_" + stock;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var lst = newsCacheTools.Get<List<Em_Grab_GaoTime_Zx>>(key);
            if (lst == null)
            {
                Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
                lst = bll.Get公告列表_New(stock);
                newsCacheTools.Add(key, lst, 0, 20, 0);
            }
            return lst;
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "f10gonggao", stock);
            throw ex;
        }
    }

    [WebMethod(Description = "F10公告根据编号取内容")]
    public Em_Grab_GaoTime_Zx f10gonggaoNr(string id)
    {
        try
        {
            string key = "softnews_f10gonggaoNr_New_" + cachePre + "_" + id;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var c = newsCacheTools.Get<Em_Grab_GaoTime_Zx>(key);
            if (c == null)
            {
                Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
                c = bll.Get公告内容_New(id);
                if (c == null) c = new Em_Grab_GaoTime_Zx();
                newsCacheTools.Add(key, c, 0, 10, 0);
            }
            return c;
        }
        catch(Exception ex)
        {
            Sms.SendSms("softnews.asmx", "f10gonggaoNr", id);
            throw ex;
        }
    }


    [WebMethod(Description = "F10行业新闻")]
    public List<Em_Grab_GaoTime_Zx> f10HyXinWen(string stock)
    {
        try
        {
            string key = "softnews_f10HyXinWen_" + cachePre + "_" + stock;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var lst = newsCacheTools.Get<List<Em_Grab_GaoTime_Zx>>(key);
            if (lst == null)
            {
                Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
                lst = bll.Get行业新闻(stock);
                if (lst != null)
                {
                    newsCacheTools.Add(key, lst, 0, 20, 0);
                }
            }
            return lst;
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "f10HyXinWen", stock);
            throw ex;
        }
    }

    [WebMethod(Description = "F10行业公司动态")]
    public List<Em_Grab_GaoTime_Zx> f10HyGongSiDongTai(string stock)
    {
        try
        {
            string key = "softnews_f10HyGongSiDongTai_" + cachePre + "_" + stock;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var lst = newsCacheTools.Get<List<Em_Grab_GaoTime_Zx>>(key);
            if (lst == null)
            {
                Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
                lst = bll.Get行业公司动态(stock);
                if (lst != null)
                {
                    newsCacheTools.Add(key, lst, 0, 20, 0);
                }
            }
            return lst;
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "f10HyGongSiDongTai", stock);
            throw ex;
        }
    }

    [WebMethod(Description = "F10新闻评论")]
    public List<Em_Grab_GaoTime_Zx> f10XinWenPinLun(string stock)
    {
        try
        {
            string key = "softnews_f10XinWenPinLun_" + cachePre + "_" + stock;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var lst = newsCacheTools.Get<List<Em_Grab_GaoTime_Zx>>(key);
            if (lst == null)
            {
                Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
                lst = bll.Get新闻评论(stock);
                if (lst != null)
                {
                    newsCacheTools.Add(key, lst, 0, 20, 0);
                }
            }
            return lst;
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "f10XinWenPinLun", stock);
            throw ex;
        }
    }

    [WebMethod(Description = "F10新闻内容")]
    public Em_Grab_GaoTime_Zx f10XinWenNr(string newsId)
    {
        try
        {
            string key = "softnews_f10XinWenNr_" + cachePre + "_" + newsId;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var c = newsCacheTools.Get<Em_Grab_GaoTime_Zx>(key);
            Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
            if (c == null)
            {

                c = bll.GetNewsById(newsId);
                if (c != null)
                {
                    newsCacheTools.Add(key, c, 1, 0, 0);
                }
            }
            if (c == null)
            {

            }
            return c;
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "f10XinWenNr", newsId);
            throw ex;
        }
    }

    [WebMethod(Description = "F10新闻内容")]
    public Em_Grab_GaoTime_Zx f10XinWenNr_Guid(string newsId)
    {
        try
        {
            string key = "softnews_f10XinWenNr_Guid_" + cachePre + "_" + newsId;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var c = newsCacheTools.Get<Em_Grab_GaoTime_Zx>(key);
            Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
            if (c == null)
            {

                c = bll.GetNewsById_guid(newsId);
                if (c != null)
                {
                    newsCacheTools.Add(key, c, 1, 0, 0);
                }
            }
            if (c == null)
            {

            }
            return c;
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "f10XinWenNr_Guid", newsId);
            throw ex;
        }
    }

    [WebMethod]
    public List<Em_Grab_GaoTime_Zx> Get新闻评论New(string stock)
    {
        try
        {
            string key = "softnews_f10XinWenPinLun_" + cachePre + "_" + stock;
            News2CacheTools newsCacheTools = new News2CacheTools();
            var lst = newsCacheTools.Get<List<Em_Grab_GaoTime_Zx>>(key);
            if (lst != null)
            {
                return lst;
            }
            else
            {
                Em_Grab_GaoTime_ZxBLL bll = new Em_Grab_GaoTime_ZxBLL();
                lst = bll.Get新闻评论New(stock);
                if (lst != null)
                {
                    newsCacheTools.Add(key, lst, 0, 30, 0);
                }
                else
                {
                    return new List<Em_Grab_GaoTime_Zx>();
                }
                return lst;
            }
        }
        catch (Exception ex)
        {
            Sms.SendSms("softnews.asmx", "Get新闻评论New", stock);
            throw ex;
        }
    
    }

}
